package com.penghaisoft.microwms.material.web.outwarehouse.service.impl;

import com.penghaisoft.microwms.common.data.model.RawRequisitionSn;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import com.penghaisoft.microwms.common.wms.model.ProOrderInSn;
import com.penghaisoft.microwms.material.web.outwarehouse.dao.OutWhRawSnMapper;
import com.penghaisoft.microwms.material.web.outwarehouse.service.OutWhRawSnService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by 王治国 on 2018/5/18.
 */
@Service
public class OutWhRawSnServiceImpl extends BaseService implements OutWhRawSnService {

    @Autowired
    private OutWhRawSnMapper outWhRawSnMapper;


    @Override
    public Pager<RawRequisitionSn> findAll(int page, int rows, RawRequisitionSn rawRequisitionSn) {
        long size = outWhRawSnMapper.queryCount(rawRequisitionSn);
        Pager<RawRequisitionSn> pager = new Pager<>();
        List<RawRequisitionSn> result = new ArrayList<>();
        pager.setPage(page);
        pager.setRows(rows);
        if (size > 0) {
            result = outWhRawSnMapper.queryList(pager, rawRequisitionSn);
            
            RawRequisitionSn sumAmount = outWhRawSnMapper.querySumAmount(rawRequisitionSn);
			pager.setOrder("{\"amount\":\"" + sumAmount.getAmount() + "\"}");
        }
        pager.setRecords(result);
        pager.setTotalCount(size);
        return pager;
    }

    @Override
    public List<RawRequisitionSn> findAllExcel(RawRequisitionSn rawRequisitionSn) {
        return null;
    }

	/* @Title: queryRequisitionSnExp 
	 * @Description: 原材料领料出库明细导出
	 * @author jzh
	 * @date 2018年10月8日 上午10:58:17 
	 */
	@Override
	public List<RawRequisitionSn> queryRequisitionSnExp(RawRequisitionSn rawRequisitionSn) {
		// TODO Auto-generated method stub
		return outWhRawSnMapper.queryList(null, rawRequisitionSn);
	}
}
